package com.LeetCode.StackAndHeap;

import org.junit.Test;

import java.util.Arrays;
import java.util.PriorityQueue;

public class minMeetingRooms {
    public int minMeetingRooms(int[][] intervals) {
        if(intervals.length == 0 ) return 0;

        PriorityQueue<Integer> queue = new PriorityQueue<>(intervals.length);
        Arrays.parallelSort(intervals,(a,b) -> a[0] - b[0]);
        queue.add(intervals[0][1]);

        for(int i = 1; i < intervals.length; i++){
            if(intervals[i][0] >= queue.peek()){
                queue.poll();
            }

            queue.add(intervals[i][1]);
        }
        return queue.size();
    }

    @Test
    public void test(){
        int[][] intervals = {
                {0,30},{5,10},{15,20}
        };
        int[][] intervals2 = {
                {5,8},{6,8}
        };
        System.out.println(minMeetingRooms(intervals2));
    }
}
